package com.example.myapplication.ui.movie

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.myapplication.R


class DateAdapter(var datelist : List<Date_info>, val context:Context) :
    RecyclerView.Adapter<DateAdapter.ViewHolder>() {

    var prev_click = 0
    val CHECK_FLAG_Clicked = 1
    val CHECK_FLAG_UnClicked = 0
    //private val checkMap: Map<Int, Int>? = null
    //private var monItemClickListener: OnRecyclerItemClickListener? = null
    private var itemClickListener: IKotlinItemClickListener? = null

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        val date_info : TextView = view.findViewById(R.id.date_info)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.date_info, parent, false)
        val viewHolder = ViewHolder(view)

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val date_info = datelist[position]
        holder.date_info.text = date_info.date

        if (datelist[position].clicked == true){
            holder.date_info.setTextColor(Color.parseColor("#ff0000"))

        }
        else{
            holder.date_info.setTextColor(Color.parseColor("#000000"))
        }

        holder.date_info.setOnClickListener {
            itemClickListener!!.onItemClickListener(position)
        }

    }

    override fun getItemCount(): Int {
        return datelist.size
    }

    fun setOnKotlinItemClickListener(itemClickListener: IKotlinItemClickListener) {
        this.itemClickListener = itemClickListener
    }

    //自定义接口
    interface IKotlinItemClickListener {
        fun onItemClickListener(position: Int)
    }

    public fun reFresh( datelist2: List<Date_info>){
        datelist = datelist2
        notifyDataSetChanged()
    }

}